﻿using System;
using System.Collections.ObjectModel;

namespace ServerCrafter.ClassLibrary.ViewModels
{
    public sealed class PropertySet
    {
        public PropertySet(string property, string value)
        {
            Property = property;
            Value = value;
        }

        public string Property { get; set; }

        public string Value { get; set; }
    }

    public sealed class VMProperties
    {
        public ObservableCollection<PropertySet> Properties { get; set; }

        public ObservableCollection<PropertySet> Get()
        {
            Properties = new ObservableCollection<PropertySet>();

            for (var lineNumber = 0; lineNumber < PropertiesManager.lineCount; lineNumber++)
            {
                if (PropertiesManager.Data[lineNumber, 0] == null) break;
                try
                {
                    Properties.Add(new PropertySet(PropertiesManager.Data[lineNumber, 0],
                                                            PropertiesManager.Data[lineNumber, 1]));
                }
                catch (Exception exception)
                {
                    Logger.WriteWarning("Could not load properties! An unknown exception has occured.");
                    Logger.WriteWarning("\tException: " + exception);
                }
            }
            return Properties;
        }
    }
}